/**
 * 
 */
package com.changil.nowonchangilchurch.ui.item;

import android.content.Context;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.widget.ImageView;

/**
 * @author zeropol2
 *
 */
public class MainImage extends ImageView {

	/**
	 * @param context
	 */
	public MainImage(Context context) {
		super(context);
		init(context);
	}

	/**
	 * @param context
	 * @param attrs
	 */
	public MainImage(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	/**
	 * @param context
	 * @param attrs
	 * @param defStyle
	 */
	public MainImage(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context);
	}
	
	private void init(Context context) {
		this.setScaleType(ScaleType.FIT_XY);
	}
	
	@Override
	protected void onLayout(boolean changed, int left, int top, int right,
			int bottom) {
		adjustSize(getResources().getDisplayMetrics().widthPixels);
		super.onLayout(changed, left, top, right, bottom);
	}

	private void adjustSize(int width) {
		ViewPager.LayoutParams lp = (ViewPager.LayoutParams)this.getLayoutParams();
		lp.height = (width *150)/360 ; //360:150로 가로 비율 유지
		this.setLayoutParams(lp);
	}

}
